package com.empty_pro.newone;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class ConfigActivity extends AppCompatActivity {
    private float dollar_rate = 0.0f;
    private float euro_rate = 0.0f;
    private float won_rate = 0.0f;

    EditText dollar;
    EditText euro;
    EditText won;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_config);

        Intent intent = getIntent();
        dollar_rate = intent.getFloatExtra("dollar_rate", 0.0f);
        euro_rate = intent.getFloatExtra("euro_rate", 0.0f);
        won_rate = intent.getFloatExtra("won_rate", 0.0f);

        dollar = findViewById(R.id.dollarrate);
        euro = findViewById(R.id.eurorate);
        won = findViewById(R.id.wonrate);

        String s1 = String.valueOf(dollar_rate);
        String s2 = String.valueOf(euro_rate);
        String s3 = String.valueOf(won_rate);

        dollar.setText(s1);
        euro.setText(s2);
        won.setText(s3);

        /*
        SharedPreferences sp=getSharedPreferences("myrate",ConfigActivity.MODE_PRIVATE);
        SharedPreferences.Editor editor=sp.edit();
        editor.putFloat("dollar_rate",dollar_rate);
        editor.putFloat("euro_rate",euro_rate);
        editor.putFloat("won_rate",won_rate);
        editor.apply();
         */

    }
    public  void RateClick(View btn) {


        String s1 = dollar.getText().toString();
        String s2 = euro.getText().toString();
        String s3 = won.getText().toString();


        if (s1.length() == 0 || s2.length() == 0 || s3.length() == 0) {
            Toast.makeText(getApplicationContext(),"汇率不能为空",Toast.LENGTH_SHORT).show();
            return;
        }

        float dollar_rate = Float.parseFloat(s1);
        float euro_rate = Float.parseFloat(s2);
        float won_rate = Float.parseFloat(s3);

        Intent Rate = new Intent(this,RateActivity.class);
        Rate.putExtra("dollar_rate", dollar_rate);
        Rate.putExtra("euro_rate", euro_rate);
        Rate.putExtra("won_rate", won_rate);

        //Toast.makeText(getApplicationContext(),"修改成功",Toast.LENGTH_SHORT).show();

        startActivity(Rate);

    }
}